home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 April: Mac OS SDK / Dev.CD Apr 98 SDK1.toast / Development Kits (Disc 1) / Interfaces&Libraries / Universal / Interfaces / PInterfaces / Math64.p < prev    next >
Encoding:
Text File  |  1998-02-12  |  7.9 KB  |  225 lines  |  [TEXT/MPS ]

  1. {
  2.      File:        Math64.p
  3.  
  4.      Contains:    64-bit integer math Interfaces.
  5.  
  6.      Version:    Technology:    System 7.5
  7.                  Release:    Universal Interfaces 3.1
  8.  
  9.      Copyright:    © 1994-1998 by Apple Computer, Inc., all rights reserved
  10.  
  11.      Bugs?:        Please include the the file and version information (from above) with
  12.                  the problem description.  Developers belonging to one of the Apple
  13.                  developer programs can submit bug reports to:
  14.  
  15.                      devsupport@apple.com
  16.  
  17. }
  18. {$IFC UNDEFINED UsingIncludes}
  19. {$SETC UsingIncludes := 0}
  20. {$ENDC}
  21.  
  22. {$IFC NOT UsingIncludes}
  23.  UNIT Math64;
  24.  INTERFACE
  25. {$ENDC}
  26.  
  27. {$IFC UNDEFINED __MATH64__}
  28. {$SETC __MATH64__ := 1}
  29.  
  30. {$I+}
  31. {$SETC Math64Includes := UsingIncludes}
  32. {$SETC UsingIncludes := 1}
  33.  
  34. {$IFC UNDEFINED __CONDITIONALMACROS__}
  35. {$I ConditionalMacros.p}
  36. {$ENDC}
  37. {$IFC UNDEFINED __MACTYPES__}
  38. {$I MacTypes.p}
  39. {$ENDC}
  40.  
  41.  
  42. {$PUSH}
  43. {$ALIGN MAC68K}
  44. {$LibExport+}
  45.  
  46.  
  47. {--------------------------------------------------------------------------------
  48.                 These routines are intended to provide C software support for
  49.                 64 bit integer types.  Their behavior should mimic anticipated
  50.                 64 bit hardware. This implementation should replace use of the
  51.                 "wide" type found in PowerPC.
  52.  
  53.     The following routines are available for performing math on 64-bit integers:
  54.     
  55.     S64Max
  56.                 Returns the largest representable SInt64.
  57.     S64Min
  58.                 Returns the smallest (i.e. most negative) SInt64.  Note: the negative
  59.                 (absolute value) of this number is not representable in an SInt64.
  60.                 That means that S64Negate(S64Min) is not representable (in fact,
  61.                 it returns S64Min).
  62.     S64Add
  63.                 Adds two integers, producing an integer result.  If an overflow
  64.                 occurs the result is congruent mod (2^64) as if the operands and
  65.                 result were unsigned.  No overflow is signaled.
  66.     
  67.     S64Subtract
  68.                 Subtracts two integers, producing an integer result.  If an overflow
  69.                 occurs the result is congruent mod (2^64) as if the operands and
  70.                 result were unsigned.  No overflow is signaled.
  71.  
  72.     S64Negate
  73.                 Returns the additive inverse of a signed number (i.e. it returns
  74.                 0 - the number).  S64Negate (S64Min) is not representable (in fact,
  75.                 it returns S64Min).
  76.     
  77.     S64Absolute
  78.                 Returns the absolute value of the number (i.e. the number if
  79.                 it is positive, or 0 - the number if it is negative).
  80.                 See S64Negate above.
  81.                 
  82.     S64Multiply
  83.                 Multiplies two signed numbers, producing a signed result.  Overflow
  84.                 is ignored and the low-order part of the product is returned.  The
  85.                 sign of the result is not guaranteed to be correct if the magnitude
  86.                 of the product is not representable.
  87.                 
  88.     S64Div
  89.                 Divides dividend by divisor, returning the quotient.  
  90.  
  91.     S64Divide
  92.                 Divides dividend by divisor, returning the quotient.  The remainder
  93.                 is returned in *remainder if remainder (the pointer) is non-NULL.
  94.                 The sign of the remainder is the same as the sign of the dividend
  95.                 (i.e. it takes the absolute values of the operands, does the division,
  96.                 then fixes the sign of the quotient and remainder).  If the divisor
  97.                 is zero, then S64Max() will be returned (or S64Min() if the dividend
  98.                 is negative), and the remainder will be the dividend; no error is
  99.                 reported.
  100.     
  101.     S64Set
  102.                 Given an SInt32, returns an SInt64 with the same value.  Use this
  103.                 routine instead of coding 64-bit constants (at least when the
  104.                 constant will fit in an SInt32).
  105.     
  106.     S64SetU
  107.                 Given a UInt32, returns a SInt64 with the same value.
  108.     
  109.     S64Compare
  110.                 Given two signed numbers, left and right, returns an
  111.                 SInt32 that compares with zero the same way left compares with
  112.                 right.  If you wanted to perform a comparison on 64-bit integers
  113.                 of the form:
  114.                         operand_1 <operation> operand_2
  115.                 then you could use an expression of the form:
  116.                         xxxS64Compare(operand_1,operand_2) <operation> 0
  117.                 to test for the same condition.
  118.                 
  119.                 CAUTION: DO NOT depend on the exact value returned by this routine.
  120.                 Only the sign (i.e. positive, zero, or negative) of the result is
  121.                 guaranteed.
  122.  
  123.     S64And, S64Or, S64Eor and S64Not
  124.     
  125.                 Return Boolean (1 or 0) depending on the outcome of the logical
  126.                 operation.
  127.  
  128.     S64BitwiseAnd, S64BitwiseOr, S64BitwiseEor and S64BitwiseNot
  129.     
  130.                 Return the Bitwise result.
  131.                 
  132.     S64ShiftRight and S64ShiftLeft
  133.     
  134.                 The lower 7 bits of the shift argument determines the amount of 
  135.                 shifting.  S64ShiftRight is an arithmetic shift while U64ShiftRight
  136.                 is a logical shift.
  137.  
  138.     SInt64ToLongDouble
  139.                 
  140.                 Converts SInt64 to long double.  Note all SInt64s fit exactly into 
  141.                 long doubles, thus, the binary -> decimal conversion routines
  142.                 in fp.h can be used to achieve SInt64 -> long double -> decimal
  143.                 conversions.
  144.                 
  145.     LongDoubleToSInt64
  146.     
  147.                 Converts a long double to a SInt64.  Any decimal string that fits
  148.                 into a SInt64 can be converted exactly into a long double, using the
  149.                 conversion routines found in fp.h.  Then this routine can be used
  150.                 to complete the conversion to SInt64.
  151.                 
  152.     SInt64ToWide
  153.     
  154.                 Converts a SInt64 to a wide struct.  If SInt64 is implemented
  155.                 as a typedef of wide, the marco does nothing. If SInt64 is 
  156.                 implememnted as a long long, it casts the long long into a 
  157.                 wide struct.
  158.     
  159.     WideToSInt64
  160.     
  161.                 Converts a wide struct into a SInt64.  If SInt64 is implemented
  162.                 as a typedef of wide, the marco does nothing. If SInt64 is 
  163.                 implememnted as a long long, it reads the struct into a long long.
  164.     
  165.     
  166.     The corresponding UInt64 routines are also included.
  167.     
  168. --------------------------------------------------------------------------------}
  169.  
  170. FUNCTION S64Max: SInt64; C;
  171. FUNCTION S64Min: SInt64; C;
  172. FUNCTION S64Add(x: SInt64; y: SInt64): SInt64; C;
  173. FUNCTION S64Subtract(left: SInt64; right: SInt64): SInt64; C;
  174. FUNCTION S64Negate(value: SInt64): SInt64; C;
  175. FUNCTION S64Absolute(value: SInt64): SInt64; C;
  176. FUNCTION S64Multiply(xparam: SInt64; yparam: SInt64): SInt64; C;
  177. FUNCTION S64Divide(dividend: SInt64; divisor: SInt64; VAR remainder: SInt64): SInt64; C;
  178. FUNCTION S64Set(value: SInt32): SInt64; C;
  179. FUNCTION S64SetU(value: UInt32): SInt64; C;
  180. FUNCTION S32Set(value: SInt64): SInt32; C;
  181. FUNCTION S64Compare(left: SInt64; right: SInt64): LONGINT; C;
  182. FUNCTION S64And(left: SInt64; right: SInt64): BOOLEAN; C;
  183. FUNCTION S64Or(left: SInt64; right: SInt64): BOOLEAN; C;
  184. FUNCTION S64Eor(left: SInt64; right: SInt64): BOOLEAN; C;
  185. FUNCTION S64Not(value: SInt64): BOOLEAN; C;
  186. FUNCTION S64BitwiseAnd(left: SInt64; right: SInt64): SInt64; C;
  187. FUNCTION S64BitwiseOr(left: SInt64; right: SInt64): SInt64; C;
  188. FUNCTION S64BitwiseEor(left: SInt64; right: SInt64): SInt64; C;
  189. FUNCTION S64BitwiseNot(value: SInt64): SInt64; C;
  190. FUNCTION S64ShiftRight(value: SInt64; shift: UInt32): SInt64; C;
  191. FUNCTION S64ShiftLeft(value: SInt64; shift: UInt32): SInt64; C;
  192. FUNCTION U64Max: UInt64; C;
  193. FUNCTION U64Add(x: UInt64; y: UInt64): UInt64; C;
  194. FUNCTION U64Subtract(left: UInt64; right: UInt64): UInt64; C;
  195. FUNCTION U64Multiply(xparam: UInt64; yparam: UInt64): UInt64; C;
  196. FUNCTION U64Divide(dividend: UInt64; divisor: UInt64; VAR remainder: UInt64): UInt64; C;
  197. FUNCTION U64Set(value: SInt32): UInt64; C;
  198. FUNCTION U64SetU(value: UInt32): UInt64; C;
  199. FUNCTION U32SetU(value: UInt64): UInt32; C;
  200. FUNCTION U64Compare(left: UInt64; right: UInt64): LONGINT; C;
  201. FUNCTION U64And(left: UInt64; right: UInt64): BOOLEAN; C;
  202. FUNCTION U64Or(left: UInt64; right: UInt64): BOOLEAN; C;
  203. FUNCTION U64Eor(left: UInt64; right: UInt64): BOOLEAN; C;
  204. FUNCTION U64Not(value: UInt64): BOOLEAN; C;
  205. FUNCTION U64BitwiseAnd(left: UInt64; right: UInt64): UInt64; C;
  206. FUNCTION U64BitwiseOr(left: UInt64; right: UInt64): UInt64; C;
  207. FUNCTION U64BitwiseEor(left: UInt64; right: UInt64): UInt64; C;
  208. FUNCTION U64BitwiseNot(value: UInt64): UInt64; C;
  209. FUNCTION U64ShiftRight(value: UInt64; shift: UInt32): UInt64; C;
  210. FUNCTION U64ShiftLeft(value: UInt64; shift: UInt32): UInt64; C;
  211. FUNCTION UInt64ToSInt64(value: UInt64): SInt64; C;
  212. FUNCTION SInt64ToUInt64(value: SInt64): UInt64; C;
  213.  
  214.  
  215. {$ALIGN RESET}
  216. {$POP}
  217.  
  218. {$SETC UsingIncludes := Math64Includes}
  219.  
  220. {$ENDC} {__MATH64__}
  221.  
  222. {$IFC NOT UsingIncludes}
  223.  END.
  224. {$ENDC}
  225.